package com.watereast;

import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ReadCSV {
    public static void main(String[] args) {
        String file = "C:\\Users\\nietao-002\\Downloads\\JMQ2.csv";
        readCSV(file);
    }

    public static List<UserInfoPoJo> readCSV(String filePath) {
        CSVReader reader = null;
        try {
            reader = (new CSVReaderBuilder(new FileReader(filePath))).build();
            List<UserInfoPoJo> userInfo = new ArrayList<>();
            List<String[]> records = null;
            try {
                records = reader.readAll();
            } catch (CsvException e) {
                e.printStackTrace();
            }
            for (String[] next : records) {
                UserInfoPoJo userInfoPoJo = new UserInfoPoJo();
                userInfoPoJo.setOpenid(next[0]);
                userInfoPoJo.setPid(next[1]);
                userInfoPoJo.setPhone(next[2]);
                userInfo.add(userInfoPoJo);
            }
            return userInfo;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null)
                    reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
